#!/usr/bin/python

import cgi
import re

logfile = "/usr/local/rattus.net/data/tradelogs.txt"

logfh = open(logfile, "r")

print "Content-type: text/html"
print
print """
<head>
<title>Checktrades Logs</title>
</head>
<body>

<pre>
"""

datestr = ""
username = ""
for line in logfh:
  line = line.strip()
  m = re.match(r"([0-9]{4}-[0-9]+-[0-9]+) ([0-9]+:[0-9]+)", line)
  if m:
    newdatestr = m.group(1)
    if datestr and newdatestr != datestr:
      print
    datestr = newdatestr
    timestr = m.group(2)
    newdatestr = line.split(" ")[0]

    username = ""

  if not username and line and line[0] == "(":
    m = re.match(r"\(([^)]+)\)", line)
    if m:
      username = m.group(1)
      print "%s %s %s" % (datestr, timestr, username)


print """
</pre>
</body>
"""
